package Dao;

import Entity.Officer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class WithAdDao {

    //根据输入，返回所有模糊查找的职工
    public static List<Officer> byName(String str) throws IOException {
        ObjectMapper om = new ObjectMapper();

        File file = new File("files\\Officer.json");
        List<Officer> list = new ArrayList<>();
        List<Officer> officers = new ArrayList<>();
        if(file.exists() && file.length() != 0){
            list = om.readValue(file, new TypeReference<List<Officer>>() {});
        }
        for(Officer officer:list){
            if(officer.getName().contains(str)||officer.getType().contains(str)||officer.getId().contains(str)
                ||officer.getBirth().contains(str)||officer.getSpeciality().contains(str)){
                if(officer.getJurisdiction()==1) officers.add(officer);
            }
        }
        return officers;
    }
}
